/*
origin glsl source: 
#define CC_DEVICE_SUPPORT_FLOAT_TEXTURE 0
#define CC_ENABLE_CLUSTERED_LIGHT_CULLING 0
#define CC_DEVICE_MAX_VERTEX_UNIFORM_VECTORS 4096
#define CC_DEVICE_MAX_FRAGMENT_UNIFORM_VECTORS 1024
#define CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT 0
#define CC_PLATFORM_ANDROID_AND_WEBGL 0
#define CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES 0
#define CC_JOINT_UNIFORM_CAPACITY 256
#define CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS 65
#define CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS 42

precision mediump float;
uniform highp mat4 cc_matProj;
attribute vec3 a_position;
attribute vec4 a_color;
varying vec2 v_uv;
   uniform vec4 offset;
    uniform vec4 digits[22];
float getComponent(vec4 v, float i) {
  if (i < 1.0) { return v.x; }
  else if (i < 2.0) { return v.y; }
  else if (i < 3.0) { return v.z; }
  else { return v.w; }
}
vec4 vert () {
  mat2 proj = mat2(cc_matProj[0].xy, cc_matProj[1].xy);
  proj /= abs(proj[1].x + proj[1].y);
  vec2 position = proj * a_position.xy + offset.xy;
  v_uv = a_color.xy;
  if (a_color.z >= 0.0) {
    float n = getComponent(digits[int(a_color.z)], a_color.w);
    v_uv += vec2(offset.z * n, 0.0);
  }
  return vec4(position, 0.0, 1.0);
}
void main() { gl_Position = vert(); }
*/
export let glsl_49f4bf89a5588051d143d4728175ddb4 = `#define CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS 42
#define CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS 65
#define CC_JOINT_UNIFORM_CAPACITY 256
#define CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES 0
#define CC_PLATFORM_ANDROID_AND_WEBGL 0
#define CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT 0
#define CC_DEVICE_MAX_FRAGMENT_UNIFORM_VECTORS 1024
#define CC_DEVICE_MAX_VERTEX_UNIFORM_VECTORS 4096
#define CC_ENABLE_CLUSTERED_LIGHT_CULLING 0
#define CC_DEVICE_SUPPORT_FLOAT_TEXTURE 0

precision mediump float;
uniform highp mat4 cc_matProj;
attribute vec3 a_position;
attribute vec4 a_color;
varying vec2 v_uv;
   uniform vec4 offset;
    uniform vec4 digits[22];
float getComponent(vec4 v, float i) {
  if (i < 1.0) { return v.x; }
  else if (i < 2.0) { return v.y; }
  else if (i < 3.0) { return v.z; }
  else { return v.w; }
}
vec4 vert () {
  mat2 proj = mat2(cc_matProj[0].xy, cc_matProj[1].xy);
  proj /= abs(proj[1].x + proj[1].y);
  vec2 position = proj * a_position.xy + offset.xy;
  v_uv = a_color.xy;
  if (a_color.z >= 0.0) {
    float n = getComponent(digits[int(a_color.z)], a_color.w);
    v_uv += vec2(offset.z * n, 0.0);
  }
  return vec4(position, 0.0, 1.0);
}
void main() { gl_Position = vert(); }
`
import {
    mat2_V2_V2,
    abs_N,
    int_N,
    vec2_N_N,
    vec4_V2_N_N,
    sampler2D,
    samplerCube,
    float,
    float_N,
    bool,
    bool_N,
    int,
    vec4,
    vec3,
    vec2,
    mat2,
    mat3,
    mat4,
} from "../builtin/BuiltinFunc"
import {
    glSet_V2_V2,
    glSet_V4_V4,
    glSet_N_N,
    glIsLess_N_N,
    glSet_M2_M2,
    glAdd_N_N,
    glDivSet_M2_N,
    glMul_M2_V2,
    glAdd_V2_V2,
    glIsMoreEqual_N_N,
    glMul_N_N,
    glAddSet_V2_V2,
    getValueKeyByIndex,
    getOutValueKeyByIndex,
} from "../builtin/BuiltinOperator"
import {
    gl_FragData,
    gl_FragColor,
    gl_Position,
    gl_PointSize,
    gl_FragCoord,
    gl_FragDepth,
    gl_FrontFacing,
    custom_isDiscard,
} from "../builtin/BuiltinVar"
import { cpuRenderingContext } from "../../CpuRenderingContext"
import {
    AttributeData,
    FragShaderHandle,
    UniformData,
    VaryingData,
    ShaderLocalData,
    VertShaderHandle,
    StructData,
} from "../../ShaderDefine"
import {
    IntData,
    FloatData,
    Vec2Data,
    Vec3Data,
    Vec4Data,
    Mat2Data,
    Mat3Data,
    Mat4Data,
    BoolData,
    Sampler2D,
    SamplerCube,
} from "../builtin/BuiltinData"
let CC_DEVICE_SUPPORT_FLOAT_TEXTURE = new FloatData(0)
let CC_ENABLE_CLUSTERED_LIGHT_CULLING = new FloatData(0)
let CC_DEVICE_MAX_VERTEX_UNIFORM_VECTORS = new FloatData(4096)
let CC_DEVICE_MAX_FRAGMENT_UNIFORM_VECTORS = new FloatData(1024)
let CC_DEVICE_CAN_BENEFIT_FROM_INPUT_ATTACHMENT = new FloatData(0)
let CC_PLATFORM_ANDROID_AND_WEBGL = new FloatData(0)
let CC_ENABLE_WEBGL_HIGHP_STRUCT_VALUES = new FloatData(0)
let CC_JOINT_UNIFORM_CAPACITY = new FloatData(256)
let CC_EFFECT_USED_VERTEX_UNIFORM_VECTORS = new FloatData(65)
let CC_EFFECT_USED_FRAGMENT_UNIFORM_VECTORS = new FloatData(42)
class AttributeDataImpl implements AttributeData {
    a_position: Vec3Data = new Vec3Data()
    a_color: Vec4Data = new Vec4Data()
    dataKeys: Map<string, any> = new Map([
        ["a_position", cpuRenderingContext.cachGameGl.FLOAT_VEC3],
        ["a_color", cpuRenderingContext.cachGameGl.FLOAT_VEC4],
    ])
    dataSize: Map<string, number> = new Map([
        ["a_position", 1],
        ["a_color", 1],
    ])
}
class VaryingDataImpl extends VaryingData {
    v_uv: Vec2Data = new Vec2Data()

    factoryCreate() {
        return new VaryingDataImpl()
    }
    dataKeys: Map<string, any> = new Map([["v_uv", cpuRenderingContext.cachGameGl.FLOAT_VEC2]])
    copy(varying: VaryingDataImpl) {
        glSet_V2_V2(varying.v_uv, this.v_uv)
    }
}
class UniformDataImpl implements UniformData {
    cc_matProj: Mat4Data = new Mat4Data()
    offset: Vec4Data = new Vec4Data()
    digits: Vec4Data[] = [
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
        new Vec4Data(),
    ]
    dataKeys: Map<string, any> = new Map([
        ["cc_matProj", cpuRenderingContext.cachGameGl.FLOAT_MAT4],
        ["offset", cpuRenderingContext.cachGameGl.FLOAT_VEC4],
        ["digits", cpuRenderingContext.cachGameGl.FLOAT_VEC4],
    ])
    dataSize: Map<string, number> = new Map([
        ["cc_matProj", 1],
        ["offset", 1],
        ["digits", 22],
    ])
}
class ShaderLocalDataImpl implements ShaderLocalData {
    dataKeys: Map<string, any> = new Map([])
    dataSize: Map<string, number> = new Map([])
    init() {}
}
export class Impl_49f4bf89a5588051d143d4728175ddb4 extends VertShaderHandle {
    varyingData: VaryingDataImpl = new VaryingDataImpl()
    uniformData: UniformDataImpl = new UniformDataImpl()
    attributeData: AttributeDataImpl = new AttributeDataImpl()

    getComponent_V4_N(__v__: Vec4Data, __i__: FloatData): FloatData {
        let v: Vec4Data = vec4()
        glSet_V4_V4(v, __v__)
        let i: FloatData = float()
        glSet_N_N(i, __i__)

        if (glIsLess_N_N(i, float_N(1.0))) {
            let v: Vec4Data = vec4()
            glSet_V4_V4(v, __v__)
            let i: FloatData = float()
            glSet_N_N(i, __i__)

            return float_N(v.x)
        } else if (glIsLess_N_N(i, float_N(2.0))) {
            let v: Vec4Data = vec4()
            glSet_V4_V4(v, __v__)
            let i: FloatData = float()
            glSet_N_N(i, __i__)

            return float_N(v.y)
        } else if (glIsLess_N_N(i, float_N(3.0))) {
            let v: Vec4Data = vec4()
            glSet_V4_V4(v, __v__)
            let i: FloatData = float()
            glSet_N_N(i, __i__)

            return float_N(v.z)
        } else {
            let v: Vec4Data = vec4()
            glSet_V4_V4(v, __v__)
            let i: FloatData = float()
            glSet_N_N(i, __i__)

            return float_N(v.w)
        }
    }
    vert(): Vec4Data {
        let proj: Mat2Data = mat2()
        glSet_M2_M2(
            proj,
            mat2_V2_V2(
                (<any>this.uniformData.cc_matProj)[getOutValueKeyByIndex(int_N(0))].xy,
                (<any>this.uniformData.cc_matProj)[getOutValueKeyByIndex(int_N(1))].xy
            )
        )
        glDivSet_M2_N(
            proj,
            abs_N(
                glAdd_N_N(float_N((<any>proj)[getOutValueKeyByIndex(int_N(1))].x), float_N((<any>proj)[getOutValueKeyByIndex(int_N(1))].y))
            )
        )
        let position: Vec2Data = vec2()
        glSet_V2_V2(position, glAdd_V2_V2(glMul_M2_V2(proj, this.attributeData.a_position.xy), this.uniformData.offset.xy))
        glSet_V2_V2(this.varyingData.v_uv, this.attributeData.a_color.xy)
        if (glIsMoreEqual_N_N(float_N(this.attributeData.a_color.z), float_N(0.0))) {
            let n: FloatData = float()
            glSet_N_N(
                n,
                this.getComponent_V4_N(
                    (<any>this.uniformData.digits)[int_N(float_N(this.attributeData.a_color.z)).v],
                    this.attributeData.a_color.out_w
                )
            )
            glAddSet_V2_V2(this.varyingData.v_uv, vec2_N_N(glMul_N_N(float_N(this.uniformData.offset.z), n), float_N(0.0)))
        }
        return vec4_V2_N_N(position, float_N(0.0), float_N(1.0))
    }
    main(): void {
        glSet_V4_V4(gl_Position, this.vert())
    }
}
